package classtrait

/**
 *
 * @author tzp
 * @since 2021/1/16
 */
class Rational(val n: Int, val d: Int) extends Ordered[Rational] {
  require(d != 0)
  println("Created " + n + "/" + d) //会在构造函数里执行

  override def toString: String = "Rational " + n + "/" + d

  override def compare(that: Rational): Int = {
    this.n * that.d - that.n * this.d
  }
}

object Rational {
  def main(args: Array[String]): Unit = {
    val a = new Rational(1, 2)
    val b = new Rational(1, 3)
    println(a > b)
    println(a >= b)
  }
}
